import cv2
import numpy as np
import time
start = time.clock()

img = cv2.imread("test1.jpg", cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img,cv2.COLOR_RGBA2GRAY)
ret,thresh = cv2.threshold(img, 127,255, cv2.THRESH_BINARY)
cv2.imshow('binary', thresh)

ret,thresh = cv2.threshold(img, 127,255, cv2.THRESH_BINARY_INV)
cv2.imshow('binary-inv', thresh)

ret,thresh = cv2.threshold(img, 127,255, cv2.THRESH_TOZERO)
cv2.imshow('toZero', thresh)

ret,thresh = cv2.threshold(img, 127,255, cv2.THRESH_TOZERO_INV)
cv2.imshow('toZero-inv', thresh)

print(type(cv2.THRESH_BINARY_INV))
thresh = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY ,11, 2)
cv2.imshow('adap-binary', thresh)

thresh = cv2.cvtColor(thresh,cv2.COLOR_GRAY2BGRA)
end = time.clock()
print('耗时：', end - start)
cv2.waitKey(0)
cv2.destroyAllWindows()
